home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Source / MiscInspectorKit / MiscInspectorManager.m < prev    next >
Text File  |  1995-04-12  |  8KB  |  335 lines

  1. /* MiscInspectorManager.m                 
  2.  *
  3.  * This is a general class that should make it easy to implement Inspectors
  4.  * as we know them from the WM or IB...but more general purpose.
  5.  * Anyway. It's not a real inspector. It's the class the manages the selection
  6.  * and all the different inspectors.
  7.  *
  8.  * For interface-info see the header file. The comments in this file mostly
  9.  * cover only the real implementation details.
  10.  *
  11.  * Written by:         Thomas Engel
  12.  * Created:            08.02.1994 (Copyleft)
  13.  * Last modified:     25.02.1994
  14.  *
  15.  * Copyright (C) 1995 Thomas Engel
  16.  */
  17.  
  18. //#import "MiscInspectorManager.h"
  19. //#import "MiscInspector.h"
  20. //#import "MiscInspectorWrapper.h"
  21. #import <misckit/MiscSwapView.h>
  22. #import <misckit/misckit.h>
  23.  
  24. @implementation MiscInspectorManager
  25.  
  26. - init
  27. {
  28.     self = [super init];
  29.     if( !self ) return self;
  30.  
  31.     // OK. We really are an object...just load the NIB and get the
  32.     // default inspectors.
  33.     // And we'll initialize the swap Controllers to have some kind of startup
  34.     // config.
  35.     
  36.     [[self loadNibSection] addDefaultInspectors];
  37.     [self updateInspectors];
  38.     return self;
  39. }
  40.  
  41. - loadNibSection
  42. {
  43.     if( [NXApp loadNibSection:"Inspector.nib" owner:self] == nil )
  44.         NXRunAlertPanel( NULL, "Couldn't load Inspector.nib",
  45.                          "OK" ,NULL, NULL );
  46.                          
  47.     return self;
  48. }
  49.  
  50. - makeKeyAndOrderFront:sender
  51. {
  52.     // If the window is visible we will make it key. We don't have to take 
  53.     // care about the selection because [inspect] does it if the window IS
  54.     // visible.
  55.     // Otherwise we will updateInspectors and cause the swapView to swap.
  56.         
  57.     if( [window isVisible] ) 
  58.         [window makeKeyAndOrderFront:sender];
  59.     else
  60.     {
  61.         [self updateInspectors];
  62.         [swapView swapContentView:self];
  63.     }
  64.     return self;
  65. }
  66.  
  67. - inspect:anObject
  68. {
  69.     selection = anObject;
  70.     if( selection == nil ) 
  71.             selectionCount = 0;
  72.     else    selectionCount = 1;
  73.  
  74.     if( [window isVisible] )
  75.     {
  76.         [self updateInspectors];
  77.         [swapView swapContentView:self];
  78.     }
  79.     return self;
  80. }
  81.  
  82. - inspectList:aList
  83. {
  84.     // If there is not really a List of object to inspect then lets handle it
  85.     // as a simple inspection.
  86.     
  87.     if( [aList count] < 2 )
  88.         return [self inspect:[aList objectAt:0]];
  89.     
  90.     // ...ok its a true list.
  91.     
  92.     selection = aList;
  93.     selectionCount = [aList count];
  94.     if( [window isVisible] )
  95.     {
  96.         [self updateInspectors];
  97.         [swapView swapContentView:self];
  98.     }
  99.     return self;
  100. }
  101.  
  102. - selection
  103. {
  104.     return selection;
  105. }
  106.  
  107. - (unsigned)selectionCount
  108. {
  109.     return selectionCount;
  110. }
  111.  
  112. - addInspector:anInspector
  113. {
  114.     // Here we add inspectors to our list. We do NOT check if they are unique.
  115.     // Anyway.It will not make any problems.
  116.     
  117.     if( !inspectors ) inspectors = [List new];
  118.     [inspectors addObject:anInspector];
  119.     return self;
  120. }
  121.  
  122. - addDefaultInspectors
  123. {
  124.     // Here we will add the 3 default inspectors for our default NIB.
  125.     // We don't add them by setting the direct connection to the manager (self)
  126.     // becuase we couln't tell in which order they will be added. And that's
  127.     // a problem because order is very importat here.
  128.     
  129.     [notApplInspector setManager:self];
  130.     [noSelInspector setManager:self];
  131.     [multiSelInspector setManager:self];
  132.     
  133.     return self;
  134. }
  135.  
  136. - updateInspectors
  137. {
  138.     // Let's find the inspector that want to deal with our current selection.
  139.     // We will add everyone to the swapViews controller list.
  140.     // If there are many different inspectors for the same trigger only the
  141.     // last will remain in the controller list!
  142.     //
  143.     // Attention: This does not cause the swapView to update its display!!!!
  144.     //                 You might need to trigger a swap on your own.
  145.     //              Anyway. You should use this method directly. Use [inspect:].
  146.     //
  147.     // Note: Remember. If you change the controllers of a swapView you should
  148.     //         be sure that there will be a new controller 
  149.     
  150.     id        anInspector;
  151.     int        i;
  152.     
  153.     for( i=0; i<[inspectors count]; i++ )
  154.     {
  155.         anInspector = [inspectors objectAt:i];
  156.         if( [anInspector doesHandleSelection] )
  157.         {
  158.             if( [anInspector respondsTo:@selector(addWrappedControllers)] )
  159.                     [anInspector addWrappedControllers];
  160.             else    [swapView addController:anInspector];
  161.         }
  162.     }
  163.     return self;
  164. }
  165.  
  166. - setSwapView:anObject
  167. {
  168.     swapView = anObject;
  169.     [swapView setDelegate:self];
  170.     
  171.     return self;
  172. }
  173.  
  174. - swapView
  175. {
  176.     return swapView;
  177. }
  178.  
  179. - window
  180. {
  181.     return window;
  182. }
  183.  
  184. - setOkButton:aButton
  185. {
  186.     // To keep up with the state and superview stuff.
  187.  
  188.     okButton = aButton;
  189.     if( buttonsSuperview == nil ) buttonsSuperview = [okButton superview];
  190.     buttonsVisible = YES;
  191.         
  192.     return self;
  193. }
  194.  
  195. - okButton
  196. {
  197.     return okButton;
  198. }
  199.  
  200. - setRevertButton:aButton
  201. {
  202.     // To keep up with the state and superview stuff.
  203.     
  204.     revertButton = aButton;
  205.     if( buttonsSuperview == nil ) buttonsSuperview = [revertButton superview];
  206.     buttonsVisible = YES;
  207.     
  208.     return self;
  209. }
  210.  
  211. - revertButton
  212. {
  213.     return revertButton;
  214. }
  215.  
  216. - setShowButtons:(BOOL)flag
  217. {
  218.     // Here we will hide/undhide ok/revert buttons.
  219.     // By default they are disabled.
  220.  
  221.     [[okButton cell] setEnabled:NO];
  222.     [[revertButton cell] setEnabled:NO];    
  223.  
  224.     if( flag == YES )
  225.     {
  226.         if( !buttonsVisible )
  227.         {
  228.             [buttonsSuperview addSubview:okButton];
  229.             [buttonsSuperview addSubview:revertButton];
  230.             buttonsVisible = YES;
  231.         }
  232.     }
  233.     else
  234.     {
  235.         if( buttonsVisible )
  236.         {
  237.             [okButton removeFromSuperview];
  238.             [revertButton removeFromSuperview];
  239.             buttonsVisible = NO;
  240.         }
  241.     }
  242.  
  243.     return self;
  244. }
  245.  
  246. - ok:sender
  247. {
  248.     return [[swapView contentsController] ok:sender];
  249. }
  250.  
  251. - revert:sender
  252. {
  253.     return [[swapView contentsController] revert:sender];
  254. }
  255.  
  256. - touch:sender
  257. {
  258.     // This methode should be invoked when the contens of the inspector
  259.     // has changed and should be confirmed. We just change some Buttons here.
  260.  
  261.     [[okButton cell] setEnabled:YES];
  262.     [[revertButton cell] setEnabled:YES];    
  263.     [window setDocEdited:YES];
  264.     
  265.     return self;
  266. }
  267.  
  268. - textDidChange:sender
  269. {
  270.     // If we are a text-objects delegate we get an easy touch-handling.
  271.     // Well normally we will never be e texts delegate but the single
  272.     // inspectors use this method when they are delegates.
  273.  
  274.     [self touch:self];
  275.     return self;
  276. }
  277.  
  278. /*
  279.  * These are the delegate-methods we provide for our swapView. This is were
  280.  * we make our view come to front after command-key actions. We do them after
  281.  * the swap to make it nicer. Only if the window was not visible up to then.
  282.  */
  283.  
  284. - viewWillSwap:sender
  285. {
  286.     // Befor the swap we have to ensure that the controllerList is up to date.
  287.     // Otherwise the swapView would choose a wrong controller and display
  288.     // the wrong one.
  289.     
  290.     if( ![window isVisible] ) [self updateInspectors];
  291.  
  292.     return self;
  293. }
  294.  
  295. - viewDidSwap:sender
  296. {
  297.     if( ![window isVisible] ) [window makeKeyAndOrderFront:self];
  298.  
  299.     return self;
  300. }
  301.  
  302. @end
  303.  
  304. /*
  305.  * History: 25.02.94 Seems like I forgot the ok,revert here ... hmm
  306.  *
  307.  *            22.02.94 Made it new-swapView-conform.
  308.  *
  309.  *            11.02.94 Remove some little 'feature-bugs'
  310.  *
  311.  *            08.02.94 A complete redesign for the MiscKit. Only the basic idea
  312.  *                     remains the same as in earlier versins.
  313.  *
  314.  *            15.01.94 Added automatich window title setting to -revert.
  315.  *
  316.  *            11.01.94 Did make the ok and revert method more firendly.
  317.  *                     They know let the viewController know whats going on. 
  318.  *
  319.  *            08.01.94 Updated to our new swapController.
  320.  *
  321.  *            18.12.93 Many methods get their first code. It all should end up
  322.  *                     with easy new-inspectors just a click away...
  323.  *
  324.  *            14.12.93 Just added some code for object inspection. Well some
  325.  *                     pieces of the code should be moved to the MultipagePanel
  326.  *
  327.  *            25.11.93 Created a copy of the pref-manager.
  328.  *
  329.  *
  330.  * Bugs: - inspect(List):
  331.  *           does check only [window isVisilbe] this is not what I really want.
  332.  *           I should aviod updating inside miniwindows ! Saves some drawing time
  333.  *           But Inspectors are seldom minimizable so this might not be too 
  334.  *         serious.
  335.  */